package com.neuedu.corejava.ch6.game;

import javax.swing.text.StyledEditorKit.ForegroundAction;

//类指的是类型，是由多个具有相同特征的事物（对象），抽象出来的
public class GameRole {
	
	//名字
	private String name;
	//武器
	private String weapon;
	//战斗力
	private int attack;
	//耐力
	private int endurance;
	public static void main(String[] args) {
		//类与对象的关系
		//对象抽象出类，类实例化为对象
		GameRole sun=new GameRole("孙悟空","金箍棒",5,5);
		sun.fighting();
		sun.defense();
		
		GameRole tang=new GameRole("唐僧","无",0,5);
		tang.fighting();
		tang.defense();
		GameRole sha=new GameRole("沙僧","月牙铲",3,4);
		sha.fighting();
		sha.defense();
		
		GameRole zhu=new GameRole("猪八戒","耙子",4,2);
		zhu.fighting();
		zhu.defense();
		
		GameRole rGameRole=null;
		for(int i=0;i<1000000;i++){
			//在循环外，超出生命周期的对象都是垃圾，可以进行回收
			GameRole gameRole=new GameRole();
		}
		System.gc();//通知垃圾回收器回收垃圾，jvm收到通知后，会调度gc进行内存回收
		//内存泄漏：当有一个堆内存一直有栈指针执行它，者块堆内存则无法进行回收；这种情况称为内存泄漏
	}
	
	//一个类编写了带参构造方法后，会屏蔽默认的空参构造方法（有带参的构造方法时，一般都要写无参的构造方法）
	//如果需要使用空参构造方法，必须显式编写一个
	public GameRole() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	
	public GameRole(String name, String weapon, int attack, int endurance) {
		super();
		this.name = name;
		this.weapon = weapon;
		this.attack = attack;
		this.endurance = endurance;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getWeapon() {
		return weapon;
	}
	public void setWeapon(String weapon) {
		this.weapon = weapon;
	}
	public int getAttack() {
		return attack;
	}
	public void setAttack(int attack) {
		this.attack = attack;
	}
	public int getEndurance() {
		return endurance;
	}
	public void setEndurance(int endurance) {
		this.endurance = endurance;
	}
	
	//战斗
	public void fighting(){
		System.out.println(name+"在战斗");
	}
	//防御
	public void  defense() {
		System.out.println(name+"在防御");
	}
	public void name() {
		
	}
	
}
